import org.apache.commons.net.telnet.EchoOptionHandler;
import org.apache.commons.net.telnet.InvalidTelnetOptionException;
import org.apache.commons.net.telnet.SuppressGAOptionHandler;
import org.apache.commons.net.telnet.TelnetClient;
import org.apache.commons.net.telnet.TerminalTypeOptionHandler;
public class VyattaTelnet 
{
	 static TelnetClient tc=null;
	 @SuppressWarnings("unused")
	VyattaTelnet()
	 {
		LoginDetails ld=new LoginDetails();
		String remoteip=ld.getHost();
		int remoteport=23;
		tc = new TelnetClient();
        TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT200", false, false, true, false);
        EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false);
        SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true);
        try
        {
            tc.addOptionHandler(ttopt);
            tc.addOptionHandler(echoopt);
            tc.addOptionHandler(gaopt);
        }
        catch (InvalidTelnetOptionException e)
        {
            System.err.println("Error registering option handlers: " + e.getMessage());
        }
        try
        {
        	tc.connect(remoteip, remoteport);
        	VyattaTerminalOutput vteriminal = new VyattaTerminalOutput(tc.getInputStream(),tc.getOutputStream());
        	System.out.println("loginbuffer="+vteriminal.getStrbuff()); 
        	vteriminal.getOutput().write("vyatta\n".getBytes()); 
         	vteriminal.getOutput().flush(); 
         	Thread.sleep(2000);
         	vteriminal.getOutput().write("vyatta\n".getBytes()); 
         	vteriminal.getOutput().flush(); 
        	VyattaCommands vc=new VyattaCommands(vteriminal); 
        }
        catch (Exception e)
        {
            System.err.println("Error registering option handlers: " + e.getMessage());
        }
	}
}